package com.meihua.baoleyi.adapters;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;

import com.meihua.baoleyi.R;
import com.meihua.baoleyi.bean.InfantSelBean;

import java.util.ArrayList;

/**
 * Created by ${zhangyuanchao} on 2017/10/26.
 */

public class SelectDiseaseRVAdapter extends RecyclerView.Adapter<SelectDiseaseRVAdapter.MViewHolder> {
    private ArrayList<InfantSelBean.DataBean> mData;

    public SelectDiseaseRVAdapter(ArrayList<InfantSelBean.DataBean> mData) {
        this.mData = mData;
    }

    @Override
    public MViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_disease, parent, false));
    }

    @Override
    public void onBindViewHolder(MViewHolder holder, int position) {
        holder.setData(mData.get(position));
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public interface OnItemClickListener {
        void onItemClick(String id, boolean isChec);
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }

    private OnItemClickListener mOnItemClickListener;

    class MViewHolder extends RecyclerView.ViewHolder {
        CheckBox iv_check;

        public MViewHolder(View itemView) {
            super(itemView);
            iv_check = itemView.findViewById(R.id.item_cb);
        }

        public void setData(final InfantSelBean.DataBean dataBean) {
            iv_check.setText(dataBean.getName());

            this.iv_check.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mOnItemClickListener.onItemClick(dataBean.getId()+"", iv_check.isChecked());
                }
            });
        }
    }

}
